package com.edu.test;

import com.edu.handler.Loghandler;
import com.edu.service.StudentService;
import com.edu.service.UserService;
import com.edu.service.impl.StudentServiceImpl;
import com.edu.service.impl.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Proxy;

public class MyProxy {
    @Test
    public void test01(){
        UserService userService = new UserServiceImpl();
        UserService userService1 = (UserService)Proxy.newProxyInstance(userService.getClass().getClassLoader(), userService.getClass().getInterfaces(), new Loghandler(userService));
        userService1.addUser();
    }

    @Test
    public void test02(){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        UserService userService = context.getBean(UserService.class);
        StudentService studentService = context.getBean(StudentService.class);
        userService.addUser();
        studentService.addStu();
    }

    @Test
    public void test03(){
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        StudentService studentService = context.getBean(StudentService.class);
        studentService.addStu();
    }
}
